﻿using System;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Web.UI;

using DevExpress.Web.ASPxHeadline;

using LMD.Constant;
using LMD.Lib.Controls;
using LMD.Lib.DataClass;

/// <summary>
/// Summary description for Extension
/// </summary>
public static class UserProfileManager
{
    public static String BuildFieldset_UserProfile(this UserData ud)
    {
        String sxOutput = String.Empty;

        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Organisasi", ud.sxOrganization);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Jabatan", ud.sxJobPosition);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Alamat E-mail", ud.sxEmailAddress);

        var udDic = ud.GetCustomDataDictionary();

        if (udDic != null)
        {
            Cached.UserDataTypeTable ccUserData = new Cached.UserDataTypeTable();
            DataTable dtUserData = ccUserData.GetUserDataType();
            sxOutput += CustomControls.BuildFieldSet_PairedInfo(dtUserData, "ID", "CODE", "CONTROL_TYPE_ID", udDic);
        }

        return sxOutput;
    }
    public static String BuildEditor_UserProfile(this UserData ud)
    {
        String sxOutput = String.Empty;
        Cached.UserDataTypeTable ccUserData = new Cached.UserDataTypeTable();
        DataTable dtUserData = null;

        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Organisasi", ud.sxOrganization);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Jabatan", ud.sxJobPosition);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Alamat E-mail", ud.sxEmailAddress);

        var udDic = ud.GetCustomDataDictionary();

        if (udDic.Count < 1)
        {
            udDic.Add(String.Empty, String.Empty);
        }
        else
        {
            dtUserData = ccUserData.GetUserDataType();
        }

        sxOutput += CustomControls.BuildEditor_ComboBoxAndText(ud.ID,
            KLOV.UserProfile.USERDATATYPE, KControl.INPUT_ID, dtUserData, "ID", "CODE", udDic);
        sxOutput += CustomControls.Create_HiddenDiv(KUserProfile.HF_USERDATACOUNT,
            udDic.Count.ToString());

        return sxOutput;

    }

    public static String BuildEditor_ProfilePicturePopup(String sxUserId)
    {
        String sxReturn = String.Empty;

        

        String sxUploadControl = CustomControls.BuildEditor_FileUpload(KUserProfile.PROFILE_PICTURE,
            KFileHandler.UserProfile.PROFILE_PICTURE, null, KControl.INPUT_ID, TextboxType.ImageUpload);

        String sxEditor = CustomControls.BuildFieldSet_PairedLabel("Profile Picture", sxUploadControl);

        sxReturn = String.Format(
            "<div id=\"{1}_{0}\" class=\"popLOV\">" +
                "<fieldset class=\"m_fs_border\" id=\fs_lov_{0}\">" +
                    "<legend>" +
                        "<a class=\"lnk\" href=\"javascript:toggle('{0}');\">Upload Profile Picture</a>" +
                    "</legend>" +
                    "<dl class=\"m_fs\"><div id=\"div_{0}\">{2}</div></dl>" +
                    "<div id=\"load_{0}\" style=\"float: right; padding-right: 10px;\"></div>" +
                    "<br/>" +
                    "<br/>" +
                    "<input type=\"button\" id=\"lnkdscd_{0}\" class=\"btn\" style=\"float: right; margin-left: 5px; margin-right: 15px;\"" +
                        " onclick=\"closeEditor();\" value=\"close\" />" +
                "</fieldset>" +
            "</div>",
            sxUserId,
            KControl.GENERICPOPFORM_ID,
            sxEditor
            );
        return sxReturn;
    }
    
}
